
* Generate yearly count of referendums, 1771-2015, including years with no referendums
clear
set obs 245
gen year = _n + 1770
append using "PaxPopuli_SDrefs_1776_2015.dta"
gen sdref = 1 if id != .
replace sdref = 0 if id == .
collapse (sum) sdref, by(year)
rename sdref sdref_total

* 10-year moving average
tsset year
gen ma = (L4.sdref_total + L3.sdref_total + L2.sdref_total + L1.sdref_total + sdref_total + F1.sdref_total + F2.sdref_total + F3.sdref_total + F4.sdref_total) / 10 


* Drop 1771-1774
drop if year < 1775

* Graph
graph twoway 	(bar sdref_total year, sort barwidth(1) fcolor(gs12) lcolor(gs12) fintensity(100))  ///
				(line ma year, sort lcolor(black) lpattern(solid) lwidth(medium)) ///
				, ///
					xscale(nofextend noextend) ///
					yscale(nofextend noextend) ///
					xlabel(1780(20)2020, angle(forty_five) valuelabels) xmtick(1770(20)2010) ///
					ylabel(0(10)30, angle(horizontal) nogrid nogextend) ymtick(1(1)30, nolabels) ///
					xtitle("", margin(medsmall)) ///
					ytitle("Number of" "self-determination referendums", size(medsmall) margin(zero)) ///
					xtitle("Year", size(medsmall) margin(tiny)) ///
					legend(off)  ///
					scheme(s2mono) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
					plotregion(margin(l=3 r=5 b=0 t=5)) ysize(6) xsize(9) scale(1.2) graphregion(margin(zero))
